/*
    wftables.c

    Copyright (C) 2007  David Crawley

    This file is part of OpenDAB.

    OpenDAB is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenDAB is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenDAB.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
** Bit rate(kbit/s), Sub-Channel size (CU), Protection level
** Audio service component protection profiles
**
** Taken from ETSI EN 300 401 V1.3.3 (2001-05), 
** 6.2, Table 7, P.45 and 11.3.1, Table 36, P.158
**
** NOTE: unused entries are numbered -1 and
** 0 <= PI < 23
*/
#include "prot.h"

const struct uepprof ueptable[] = {
        {32, 16, 5, {3, 4, 17, 0}, {4, 2, 1, -1}, 0},
        {32, 21, 4, {3, 3, 18, 0}, {10, 5, 4, -1}, 0},
        {32, 24, 3, {3, 4, 14, 3}, {14, 8, 5, 7}, 0},
        {32, 29, 2, {3, 4, 14, 3}, {21, 12, 7, 12}, 0},
        {32, 35, 1, {3, 5, 13, 3}, {23, 16, 11, 16}, 4},
        {48, 24, 5, {4, 3, 26, 3}, {4, 3, 1, 2}, 0},
        {48, 29, 4, {3, 4, 26, 3}, {8, 5, 3, 5}, 0},
        {48, 35, 3, {3, 4, 26, 3}, {14, 9, 5, 8}, 4},
        {48, 42, 2, {3, 4, 26, 3}, {23, 13, 7, 14}, 0},
        {48, 52, 1, {3, 5, 25, 3}, {23, 17, 12, 17}, 0},
        {56, 29, 5, {6, 10, 23, 3}, {4, 3, 1, 2}, 0},
        {56, 35, 4, {6, 10, 23, 3}, {8, 5, 3, 4}, 0},
        {56, 42, 3, {6, 12, 21, 3}, {15, 6, 5, 8}, 0},
        {56, 52, 2, {6, 10, 23, 3}, {22, 12, 7, 12}, 8},
        {64, 32, 5, {6, 9, 31, 2}, {4, 2, 1, 2}, 0},
        {64, 42, 4, {6, 9, 33, 0}, {10, 5, 4, -1}, 0},
        {64, 48, 3, {6, 12, 27, 3}, {15, 7, 5, 8}, 0},
        {64, 58, 2, {6, 10, 29, 3}, {22, 12, 7, 12}, 8},
        {64, 70, 1, {6, 11, 28, 3}, {23, 17, 11, 17}, 4},
        {80, 40, 5, {6, 10, 41, 3}, {5, 2, 1, 2}, 0},
        {80, 52, 4, {6, 10, 41, 3}, {10, 5, 4, 5}, 0},
        {80, 58, 3, {6, 11, 40, 3}, {15, 7, 5, 6}, 0},
        {80, 70, 2, {6, 10, 41, 3}, {22, 12, 7, 12}, 8},
        {80, 84, 1, {6, 10, 41, 3}, {23, 16, 11, 17}, 4},
        {96, 48, 5, {7, 9, 53, 3}, {4, 3, 1, 3}, 0},
        {96, 58, 4, {7, 10, 52, 3}, {8, 5, 3, 5}, 0},
        {96, 70, 3, {6, 12, 51, 3}, {15, 8, 5, 9}, 4},
        {96, 84, 2, {6, 10, 53, 3}, {21, 11, 8, 11}, 0},
        {96, 104, 1, {6, 13, 50, 3}, {23, 17, 12, 18}, 0},
        {112, 58, 5, {14, 17, 50, 3}, {4, 3, 1, 4}, 0},
        {112, 70, 4, {11, 21, 49, 3}, {8, 5, 3, 7}, 0},
        {112, 84, 3, {11, 23, 47, 3}, {15, 7, 5, 8}, 0},
        {112, 104, 2, {11, 21, 49, 3}, {22, 11, 8, 13}, 4},
        {128, 64, 5, {12, 19, 62, 3}, {4, 2, 1, 3}, 0},
        {128, 84, 4, {11, 21, 61, 3}, {10, 5, 4, 6}, 0},
        {128, 96, 3, {11, 22, 60, 3}, {15, 8, 5, 9}, 4},
        {128, 116, 2, {11, 21, 61, 3}, {21, 11, 8, 13}, 0},
        {128, 140, 1, {11, 20, 62, 3}, {23, 16, 12, 18}, 8},
        {160, 80, 5, {11, 19, 87, 3}, {4, 3, 1, 3}, 0},
        {160, 104, 4, {11, 23, 83, 3}, {10, 5, 4, 8}, 0},
        {160, 116, 3, {11, 24, 82, 3}, {15, 7, 5, 10}, 0},
        {160, 140, 2, {11, 21, 85, 3}, {21, 10, 8, 12}, 0},
        {160, 168, 1, {11, 22, 84, 3}, {23, 17, 11, 18}, 0},
        {192, 96, 5, {11, 20, 110, 3}, {5, 3, 1, 4}, 0},
        {192, 116, 4, {11, 22, 108, 3}, {9, 5, 3, 8}, 0},
        {192, 140, 3, {11, 24, 106, 3}, {15, 9, 5, 10}, 0},
        {192, 168, 2, {11, 20, 110, 3}, {21, 12, 8, 12}, 8},
        {192, 208, 1, {11, 21, 109, 3}, {23, 19, 12, 23}, 0},
        {224, 116, 5, {12, 22, 131, 3}, {7, 5, 1, 5}, 4},
        {224, 140, 4, {12, 26, 127, 3}, {11, 7, 3, 10}, 0},
        {224, 168, 3, {11, 20, 134, 3}, {15, 9, 6, 8}, 0},
        {224, 208, 2, {11, 22, 132, 3}, {23, 15, 9, 14}, 0},
        {224, 232, 1, {11, 24, 130, 3}, {23, 19, 11, 19}, 4},
        {256, 128, 5, {11, 24, 154, 3}, {5, 4, 1, 4}, 0},
        {256, 168, 4, {11, 24, 154, 3}, {11, 8, 4, 9}, 4},
        {256, 192, 3, {11, 27, 151, 3}, {15, 9, 6, 9}, 0},
        {256, 232, 2, {11, 22, 156, 3}, {23, 13, 9, 12}, 8},
        {256, 280, 1, {11, 26, 152, 3}, {23, 18, 13, 17}, 4},
        {320, 160, 5, {11, 26, 200, 3}, {7, 4, 1, 5}, 4},
        {320, 208, 4, {11, 25, 201, 3}, {12, 8, 4, 9}, 8},
        {320, 280, 2, {11, 26, 200, 3}, {23, 16, 8, 16}, 0},
        {384, 192, 5, {11, 27, 247, 3}, {7, 5, 1, 6}, 0},
        {384, 280, 3, {11, 24, 250, 3}, {15, 8, 6, 9}, 4},
        {384, 416, 1, {12, 28, 245, 3}, {23, 19, 13, 22}, 8}
};

/*
** Tables 8, 9, 39, 41: EEP Sub-channel sizes/coding rates etc.
** ETSI EN 300 401 V1.3.3 (2001-05), 6.2, P.46 & 11.3.2, P.159
*/
const struct eepprof eeptable[] = {
	{12, 8, {{6, -3}, {0, 3}}, {23, 22}},
	{8, 8, {{2, -3}, {4, 3}}, {13, 12}},
	{6, 8, {{6, -3}, {0, 3}}, {7, 6}},
	{4, 8, {{4, -3}, {2, 3}}, {2, 1}},
	{27, 32, {{24, -3}, {0, 3}}, {9, 8}},
	{21, 32, {{24, -3}, {0, 3}}, {5, 4}},
	{18, 32, {{24, -3}, {0, 3}}, {3, 2}},
	{15, 32, {{24, -3}, {0, 3}}, {1, 0}}
};
/* Special case for EEP 2-A when bitate == 8 */
const struct eepprof eep2a8kbps = {
	8, 8, {{0, 5}, {0, 1}}, {3, 12}
};

/*
** Table 34: Puncturing vectors
** ETSI EN 300 401 V1.3.3 (2001-05), 11.1.2, P.155
*/
const char pvec[][32] = {
	{1,1,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0},
	{1,1,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0},
	{1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0},
	{1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0},
	{1,1,0,0, 1,1,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,0,0,0},
	{1,1,0,0, 1,1,0,0, 1,1,0,0, 1,0,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,0,0,0},
	{1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,0,0,0},
	{1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0, 1,1,0,0},
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